package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.constant.RedisConst;
import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.product.entity.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.atguigu.gmall.product.vo.SaveSkuVo;
import com.atguigu.starter.cache.service.Bitmapservice;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:lyd
 * @Date:2023/8/16 18:52
 * @Version:1.0
 * @Description
 **/

@RestController
@RequestMapping("/admin/product")
public class SkuController {


    @Autowired
    private SkuInfoService skuInfoService;

    @Autowired
    private Bitmapservice bitmapservice;

    /**
     * 获取sku分页列表
     */
    @GetMapping("/list/{page}/{limit}")
    public Result getSkuPage(@PathVariable Long page,
                             @PathVariable Long limit) {

        Page<SkuInfo> pages = skuInfoService.lambdaQuery()
                .page(new Page<>(page, limit));
        return Result.ok(pages).message("成功");
    }


    /**
     * 保存sku
     * @param vo
     * @return
     */
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SaveSkuVo vo) {
        skuInfoService.saveSkuInfo(vo);
        return Result.ok().message("成功");
    }

    /**
     * 商品上架
     * @param skuId
     * @return
     */
    @GetMapping("/onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId) {
        skuInfoService.onSale(skuId);
        return Result.ok("成功");
    }

    /**
     * 商品下架
     * @param skuId
     * @return
     */
    @GetMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId) {
        skuInfoService.cancelSale(skuId);
        return Result.ok("成功");
    }

    /**
     * 初始化商品id,全量缓存skuId在redis中
     * @return
     */
    @GetMapping("/initSkuId")
    public Result initAllSkuId() {
       skuInfoService.initAllSkuId();
        return Result.ok().message("成功");
    }

}
